package algorithm.middle;


import java.util.HashMap;
import java.util.Map;

/**
 *
 */
public class AuthenticationManager1797 {

    int over;
    Map<String, Long> map;

    public AuthenticationManager1797(int timeToLive) {
        over = timeToLive;
        map = new HashMap<>();
    }

    public void generate(String tokenId, int currentTime) {
        map.put(tokenId, (long) (currentTime + over));
    }

    public void renew(String tokenId, int currentTime) {
        Long integer = map.get(tokenId);
        if (integer != null && integer>currentTime)  {
            map.put(tokenId, (long) (currentTime + over));
        }
    }

    public int countUnexpiredTokens(int currentTime) {
        int coutnt = 0;
        for (Long value : map.values()) {
            if (value > currentTime) {
                coutnt++;
            }
        }
        return coutnt;
    }

}
